<?php

namespace addons\sum\controller;


use addons\sum\controller\Base;

class Richtext extends Base
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    // 富文本 列表
    public function index()
    {
        $search=$this->request->get('search');
        $type=$this->request->get('type');
        $map=[];
        if($search){
            $map['title'] = ['like', '%'.$search.'%'];
        }
        if($type){
            $map['type'] =$type;
        }
        $records=\addons\sum\model\Richtext::where($map)->order('id', 'DESC')->paginate(10);
        $records->each(function ($record){
            $lang_record=$this->doLangData($record['lang_data']);
            //合并数组 - 在模型中配置属性，如 image 使用 cdnurl,是在最终的结果时处理的。所以这里直接覆盖 image 就行，不用提前在处理数据
            if(!empty($lang_record)){
                foreach ($lang_record as $lk=>$lv){
                    $record[$lk]=$lv;
                }
            }
            unset($record['lang_data']);
        });
        $this->success('获取成功', $records);
    }
    public function detail() {
        $id = $this->request->get('id');
        $map=[];
        if($id){
            $map['id']=$id;
        }
        $slug = $this->request->get('slug');
        if($slug){
            $map['slug']=$slug;
        }
        $record = \addons\sum\model\Richtext::where($map)->find();
        $lang_record=$this->doLangData($record['lang_data']);
        //合并数组 - 在模型中配置属性，如 image 使用 cdnurl,是在最终的结果时处理的。所以这里直接覆盖 image 就行，不用提前在处理数据
        if(!empty($lang_record)){
            foreach ($lang_record as $lk=>$lv){
                $record[$lk]=$lv;
            }
        }
        unset($record['lang_data']);
        $this->success($data->title??'操作成功', $record);
    }

}
